/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       standard_fonts.h

	$Header: /game/standard_fonts.h $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "standard_fonts.h"

#include "elements_of.h"

namespace {

	struct t_sized_font
	{
		int           size;
		t_font_cache* font;
	};

	std::string const k_font_family_name = "prose_antique";

	struct t_search_font
	{
		bool operator()( t_sized_font const& font, int size ) const
		{
			return font.size < size;
		}
	};

	t_font_cache g_font_9( "small fonts5" );
	t_font_cache g_font_11( "small fonts6");

	t_font_cache g_font_12( k_font_family_name + ".12" );
	t_font_cache g_font_14( k_font_family_name + ".14" );
	t_font_cache g_font_16( k_font_family_name + ".16" );
	t_font_cache g_font_18( k_font_family_name + ".18" );
	t_font_cache g_font_20( k_font_family_name + ".20" );
	t_font_cache g_font_22( k_font_family_name + ".22" );
	t_font_cache g_font_24( k_font_family_name + ".24" );
	t_font_cache g_font_26( k_font_family_name + ".26" );
	t_font_cache g_font_28( k_font_family_name + ".28" );
	t_font_cache g_font_30( k_font_family_name + ".30" );
	t_font_cache g_font_32( k_font_family_name + ".32" );
	t_font_cache g_font_34( k_font_family_name + ".34" );
	t_font_cache g_font_36( k_font_family_name + ".36" );

	t_sized_font g_fonts[] =
	{
		{ 9, &g_font_9 },
		{ 11, &g_font_11 },
		{ 12, &g_font_12 },
		{ 14, &g_font_14 },
		{ 16, &g_font_16 },
		{ 18, &g_font_18 },
		{ 20, &g_font_20 },
		{ 23, &g_font_22 },
		{ 25, &g_font_24 },
		{ 27, &g_font_26 },
		{ 29, &g_font_28 },
		{ 30, &g_font_30 },
		{ 33, &g_font_32 },
		{ 34, &g_font_34 },
		{ 36, &g_font_36 },
	};
};

t_cached_font get_font( int size )
{
	t_sized_font* begin = g_fonts;
	t_sized_font* end   = g_fonts + ELEMENTS_OF( g_fonts ) - 1;
	t_sized_font* result = std::lower_bound( begin, end, size, t_search_font() );

	if (result != begin && result->size > size)
		result--;
	return result->font->get();
}
